/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package EventHandler;

import app.bus.AccountModel;
import app.entities.Account;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import mvc.Event;

/**
 *
 * @author Tuan Long
 */
public class Login implements Event{

    @Override
    public String EventHandler(HttpServletRequest request, HttpServletResponse response) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        Account a = AccountModel.checkLoginValid(username, password);
        if(a != null){            
            saveLogin(a,request.getSession(true));
        }
        return "index.jsp";
    }

    private void saveLogin(Account a, HttpSession session) {
        session.setAttribute("online", a);
    }
    
}
